package se.webbzon.boltzmann.game.sequence.condition;

import se.webbzon.boltzmann.game.object.player.AbstractPlayerCharacter;
import se.webbzon.boltzmann.game.sequence.Sequence;
import se.webbzon.boltzmann.inventory.Inventory;
import se.webbzon.oschi01.worldobject.WorldObject;

public class CanStore extends ConditionSequenceNode {

	/*============================================================
	Constructors
	============================================================*/

	public CanStore(Sequence sequence) {
		super(sequence,null,null);
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public boolean isTrue() {
		WorldObject storage = getSequence().getBinding(this);
		if (storage == null)
			storage = getSequence().getBinding("player");
		if (storage == null)
			storage = getSequence().getBinding("parent");
		if (storage == null)
			return false;
		else if (storage instanceof AbstractPlayerCharacter) {
			Inventory inv = ((AbstractPlayerCharacter) storage).getPlayer().getInventory();
			return inv.getNumberOfItems() < inv.getMaxItems();
		} else
			return false;
	}
	
}
